package com.cgq.base.entity;

import net.sf.json.JSONObject;

public class AjaxResult {

	private boolean success=false;
	
	private String title;

	private String message;
	
	private Object data;

	private AjaxResult(boolean success,String title,String message,Object data){
		this.title=title;
		this.success=success;
		this.message=message;
		this.data=data;
	}

	public static AjaxResult success(){
		return new AjaxResult(true,null,null,null);
	}
	
	/**
	 * 成功并返回消息
	 * @param message 消息正文
	 * @return
	 */
	public static AjaxResult success(String message){
		return new AjaxResult(true,null,message,null);
	}
	
	/**
	 * 成功并返回消息
	 * @param title 标题
	 * @param message 消息正文
	 * @return
	 */
	public static AjaxResult success(String title,String message){
		return new AjaxResult(true,title,message,null);
	}
	
	/**
	 * 成功并返回数据
	 * @param data
	 * @return
	 */
	public static AjaxResult success(Object data){
		return new AjaxResult(true,null,null,data);
	}
	
	public static AjaxResult successResult(Object data){
		return new AjaxResult(true,null,null,data);
	}
	public static AjaxResult error(){
		return new AjaxResult(false,null,null,null);
	}
	
	/**
	 * 失败并返回消息
	 * @param message 消息正文
	 * @return
	 */
	public static AjaxResult error(String message){
		return new AjaxResult(false,null,message,null);
	}
	
	/**
	 * 失败并返回消息
	 * @param title   标题
	 * @param message 消息正文
	 * @return
	 */
	public static AjaxResult error(String title,String message){
		return new AjaxResult(false,title,message,null);
	}
	

	
	
	
	
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	@Override
	public String toString() {
		String str = JSONObject.fromObject(this).toString();
		return str;
	}
	
}